import { Geometry } from "./Geometry";
import { all, any, has } from "../core/logic";
import { process } from "../process/worker/process";
/**
 * @class
 * @memberof w.geometry
 */
class CylinderGeometry extends Geometry {
  /**
   * 圆柱体构造方法
   * @param {*} opts
   * @param {Number} opts.radiusTop 【可选值】圆柱体顶部半径，缺省值：1。
   * @param {Number} opts.radiusBottom 【可选值】圆柱体底部半径，缺省值：1。
   * @param {Number} opts.height 【可选值】圆柱体高度，缺省值：1。
   * @param {Number} opts.radialSegments 【可选值】围绕圆柱体圆周的分段面数，缺省值：32。
   * @param {Number} opts.heightSegments 【可选值】沿圆柱体高度的面的行数，缺省值：1。
   * @param {Number} opts.openEnded 【可选值】圆柱体的末端是开放的还是封闭的，缺省值：false。
   * @param {Number} opts.thetaStart 【可选值】第一段的起始角度，缺省值：0。
   * @param {Number} opts.thetaLength 【可选值】扇形的圆心角，缺省值：Math.PI * 2。
   * @param {Boolean} opts.back 【可选值】是否开启后台线程构造圆柱，缺省值：true，在后台进行解析。
   */
  constructor(opts = {}) {
    super(opts);
    this.type = "CylinderGeometry";
    this.position = null;
    this._radiusTop = any(opts.radiusTop, 1);
    this._radiusBottom = any(opts.radiusBottom, 1);
    this._height = any(opts.height, 1);
    this._radialSegments = any(opts.radialSegments, 32);
    this._heightSegments = any(opts.heightSegments, 1);
    this._openEnded = any(opts.openEnded, false);
    this._thetaStart = any(opts.thetaStart, 0);
    this._thetaLength = any(opts.thetaLength, Math.PI * 2);
    this._back = any(opts.back, false);
    this.createCylinder();
  }
  set back(v){
    this._back = v;
    return this;
  }
  get back(){
    return this._back;
  }
  set radiusTop(v){
    this._radiusTop = v;
    this.createCylinder();
    return this;
  }
  get radiusTop(){
    return this._radiusTop;
  }
  set radiusBottom(v){
    this._radiusBottom = v;
    this.createCylinder();
    return this;
  }
  get radiusBottom(){
    return this._radiusBottom;
  }
  set height(v){
    this._height = v;
    this.createCylinder();
    return this;
  }
  get height(){
    return this._height;
  }
  set radialSegments(v){
    this._radialSegments = v;
    this.createCylinder();
    return this;
  }
  get radialSegments(){
    return this._radialSegments;
  }
  set heightSegments(v){
    this._heightSegments = v;
    this.createCylinder();
    return this;
  }
  get heightSegments(){
    return this._heightSegments;
  }
  set openEnded(v){
    this._openEnded = v;
    this.createCylinder();
    return this;
  }
  get openEnded(){
    return this._openEnded;
  }
  set thetaStart(v){
    this._thetaStart = v;
    this.createCylinder();
    return this;
  }
  get thetaStart(){
    return this._thetaStart;
  }
  set thetaLength(v){
    this._thetaLength = v;
    this.createCylinder();
    return this;
  }
  get thetaLength(){
    return this._thetaLength;
  }

  createCylinder() {
    let info = {
      back: this.back,
      radiusTop: this.radiusTop,
      radiusBottom: this.radiusBottom,
      height: this.height,
      radialSegments: this.radialSegments,
      heightSegments: this.heightSegments,
      openEnded: this.openEnded,
      thetaStart: this.thetaStart,
      thetaLength: this.thetaLength,
      type: "createCylinder"
    }
    process(info, (message) => {
      let { position, indices, normal, texCood0 } = message.data;

      this.position = new Float32Array(position);
      this.normal = new Float32Array(normal);
      this.texCood0 = new Float32Array(texCood0);
      this.indices = new Uint32Array(indices);
    })
  }
}

export { CylinderGeometry }
